// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import router from './router/index'
// 引入Vuex的store对象
import store from './store'

import './assets/css/animate.css'

Vue.use(VueRouter)

// 过滤器
Vue.filter('getCN', function(value) {
  switch (value) {
    case 'PLAN':
      return '计划中';
      break;
    case 'IN_PROGRESS':
      return '进行中';
      break;
    case 'COMPLETED':
      return '已完成';
      break;
    case 0:
      return '未签约';
      break;
    case 1:
      return '已签约';
      break;
    case 'GY':
      return '国有';
      break;
    case 'JT':
      return '集体';
      break;
    default:
      return '未找到';
      break;
  }
});

import {
  ToastPlugin
} from 'vux'
Vue.use(ToastPlugin)
// echart
import chartTheme from './util/chartTheme';
import ECharts from 'vue-echarts';
Vue.component('v-chart', ECharts);
ECharts.registerTheme('macarons', chartTheme);

// 高德地图
import VueAMap from 'vue-amap';

Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: "62ca28cc39450426aa40b80573eb798b", //刚刚开发者申请哪里的key
  // key: '3a6b610570ac6f24614a906c0fe674d2',
  uiVersion: '1.0',
  plugin: [
    'AMap.Object3DLayer',
    'AMap.PolyEditor',
    'AMap.CircleEditor',
    'AMap.StyleObject',
    'AMap.MassMarks',
    'AMap.MouseTool',
    'AMap.PolyEditor',
    'AMap.Lights',
    'AMap.DistrictSearch',
    'AMap.Size',
  ],
  v: '1.4.11',
});
router.beforeEach(async (to, from, next) => {
  if (to.meta.disCheck) {
    next();
    return;
  };
  await store.dispatch("saveCurUrl", {data: to});
  const l = JSON.parse(localStorage.getItem("loginInfo"));
  console.log("l", l)
  localStorage.setItem("historyPath", to.fullPath);
  const d = new Date().getTime(); //当前时间
  if (!l) {
    router.push({ path: "/login" });
    return;
  } else {
    //存在token,判断token是否过期
    next();
  }
  next();
})

FastClick.attach(document.body)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app-box')
